package com.suedawn.bookmanagesystem.controller;

import com.suedawn.bookmanagesystem.dto.UserQueryDTO;
import com.suedawn.bookmanagesystem.entity.User;
import com.suedawn.bookmanagesystem.service.UserService;
import com.suedawn.bookmanagesystem.vo.LoginReqVo;
import com.suedawn.bookmanagesystem.vo.LoginRespVo;
import com.suedawn.bookmanagesystem.vo.R;
import com.suedawn.bookmanagesystem.vo.RegisterVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api")
@CrossOrigin(origins = "http://localhost:5174") // 更正拼写错误
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public R<LoginRespVo> login(@RequestBody LoginReqVo vo) {
        return userService.login(vo);
    }

    @PostMapping("/register")
    public R register(@RequestBody RegisterVo vo) {
        return userService.register(vo);
    }

    @GetMapping("/auth/captcha")
    public R<Map> getCaptchaCode(){
        return userService.getCaptchaCode();
    }

    @GetMapping("/user/list")
    public R list(UserQueryDTO dto){
        return userService.getUsers(dto);
//        List<User> list = userService.userList(dto);
//        return  list!=null?R.ok(list):R.error("用户查询失败");
    }

    @PutMapping("/user/reset")
    public R resetPassword(int userId){
        return userService.resetPassword(userId);
    }


}
